<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>贷款管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			function  AlltoTextarea() {
				$("#applyCondition").val(toTextarea($("#applyCondition").val()));
				$("#applyTypeNote").val(toTextarea($("#applyTypeNote").val()));
				$("#mustMaterial").val(toTextarea($("#mustMaterial").val()));
				$("#materialNote").val(toTextarea($("#materialNote").val()));
				$("#remarks").val(toTextarea($("#remarks").val()));
			}
			AlltoTextarea();
			$("#inputForm").on("submit",function () {
				//保留textarea的空格和换行存到库中
				$("#applyCondition").val(textareaTo($("#applyCondition").val()));
				$("#applyTypeNote").val(textareaTo($("#applyTypeNote").val()));
				$("#mustMaterial").val(textareaTo($("#mustMaterial").val()));
				$("#materialNote").val(textareaTo($("#materialNote").val()));
				$("#remarks").val(textareaTo($("#remarks").val()));
				return false;
			});
			/**
			 * @funciton 转换textarea存入数据库的回车换行和空格  textarea ---  数据库,用val取数据，置换'\n'
			 */
			function textareaTo(str){
				var reg=new RegExp("\n","g");
				var regSpace=new RegExp(" ","g");
				str = str.replace(reg,"<br/>");
				str = str.replace(regSpace,"&nbsp;");
				return str;
			}

			/**
			 * @funciton  数据库 ---  编辑页面  .val(str)
			 */
			function toTextarea(str){
				var reg=new RegExp("<br/>","g");
				var regSpace=new RegExp("&nbsp;","g");
				str = str.replace(reg,"\n");
				str = str.replace(regSpace," ");
				return str;
			}
		});
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/sys/loan/loan/">贷款列表</a></li>
		<li class="active"><a href="${ctx}/sys/loan/loan/form?id=${loan.id}">贷款<shiro:hasPermission name="sys:loan:loan:edit">${not empty loan.id?'修改':'添加'}</shiro:hasPermission><shiro:lacksPermission name="sys:loan:loan:edit">查看</shiro:lacksPermission></a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="loan" action="${ctx}/sys/loan/loan/save" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">贷款类型：</label>
			<div class="controls">
				<select name="typeId" class="required" style="width:100px;">
					<c:forEach items="${types}" var="type">
						<option value="${type.id}" ${type.id==loan.typeId?'selected':''} title="${type.name}">${type.name}</option>
					</c:forEach>
				</select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<%--<div class="control-group">
			<label class="control-label">手续费ID：</label>
			<div class="controls">
				<form:input path="costId" htmlEscape="false" maxlength="64" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>--%>
		<div class="control-group">
			<label class="control-label">贷款名称：</label>
			<div class="controls">
				<form:input path="name" htmlEscape="false" maxlength="255" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">最低利率：</label>
			<div class="controls">
				<form:input path="minRate" htmlEscape="false" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">最高利率：</label>
			<div class="controls">
				<form:input path="maxRate" htmlEscape="false" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">最低额度：</label>
			<div class="controls">
				<form:input path="minAmount" htmlEscape="false" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">最高额度：</label>
			<div class="controls">
				<form:input path="maxAmount" htmlEscape="false" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">图标地址：</label>
			<div class="controls">

				<c:set var="hasEdit" value="0" >	</c:set>
				<shiro:hasPermission name="sys:loan:loan:edit">	<c:set var="hasEdit" value="1" >	</c:set></shiro:hasPermission>
				<shiro:hasPermission name="sys:loan:loan:add">	<c:set var="hasEdit" value="1" >	</c:set></shiro:hasPermission>
				<c:choose>
					<c:when test="${hasEdit==1}">
						<form:hidden id="iconUrl" path="iconUrl" htmlEscape="false" maxlength="255" class="input-xlarge"/>
						<sys:ckfinder input="iconUrl"  	 type="files" uploadPath="/sys/loan/loan" selectMultiple="false"/>
					</c:when>
					<c:otherwise>
					<img src="${loan.iconUrl}" width="100px" height="100px">
					</c:otherwise>
				</c:choose>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">摘要：</label>
			<div class="controls">
				<form:input path="note" htmlEscape="false" maxlength="255" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">月利率：</label>
			<div class="controls">
				<form:input path="monthRate" htmlEscape="false" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">开发地区：</label>
			<div class="controls">
				<form:input path="area" htmlEscape="false" maxlength="255" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">期限：</label>
			<div class="controls">
				<form:input path="term" htmlEscape="false" maxlength="255" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">还款方式：</label>
			<div class="controls">
				<form:input path="paymentWay" htmlEscape="false" maxlength="255" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">提前还款：</label>
			<div class="controls">
				<form:input path="advancePayment" htmlEscape="false" maxlength="255" class="input-xlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">申请条件：</label>
			<div class="controls">
				<form:textarea path="applyCondition" htmlEscape="false" rows="4" class="input-xxlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">申请类别说明：</label>
			<div class="controls">
				<form:textarea path="applyTypeNote" htmlEscape="false" rows="4" class="input-xxlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">所需材料：</label>
			<div class="controls">
				<form:textarea path="mustMaterial" htmlEscape="false" rows="4" class="input-xxlarge required"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">材料说明：</label>
			<div class="controls">
				<form:textarea path="materialNote" htmlEscape="false" rows="4" class="input-xxlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">备注信息：</label>
			<div class="controls">
				<form:textarea path="remarks" htmlEscape="false" rows="4" maxlength="255" class="input-xxlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">所属银行：</label>
			<div class="controls">
				<select name="bankId" class="required" style="width:100px;">
					<c:forEach items="${banks}" var="bank">
						<option value="${bank.id}" ${bank.id==loan.bankId?'selected':''} title="${bank.name}">${bank.name}</option>
					</c:forEach>
				</select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否推荐标识：</label>
			<div class="controls">
				<form:select path="recomendFlag" class="input-xlarge required">
					<form:option value="" label=""/>
					<form:options items="${fns:getDictList('recomend_flag')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="sys:loan:loan:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>